<template>
  <div class="container">
    <el-form ref="dataForm" :model="conModel" label-width="72px" size="mini" class="search_content">
      <el-row :gutter="24">
        <el-col :span="4" class="common_input">
          <el-form-item label="铭牌号:">
            <el-input v-model="conModel.BarCode" clearable placeholder="请输入铭牌号" @keyup.enter.native="getList('search')" />
          </el-form-item>
        </el-col>
        <el-col :span="4" class="common_input">
          <el-form-item label="客户名称:" prop="CustomerNo">
            <el-input v-model="conModel.CustomerName" clearable placeholder="请输入客户名称" @keyup.enter.native="getList('search')" />
          </el-form-item>
        </el-col>
        <el-col :span="4" class="common_picker">
          <el-form-item label="开始时间:">
            <el-date-picker
              v-model="conModel.StartTime"
              type="datetime"
              format="yyyy-MM-dd HH:mm"
              alue-format="yyyy-MM-dd HH:mm"
              placeholder="请选择开始时间"
              size="mini"
              class="search_common_picker"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4" class="common_picker">
          <el-form-item label="结束时间:">
            <el-date-picker
              v-model="conModel.EndTime"
              type="datetime"
              format="yyyy-MM-dd HH:mm"
              alue-format="yyyy-MM-dd HH:mm"
              placeholder="请选择结束时间"
              size="mini"
              class="search_common_picker"
            />
          </el-form-item>
        </el-col>
        <!-- <el-col :span="4" class="common_input">
          <el-form-item label="支付方式:" prop="PayWayID">
            <el-select v-model="conModel.PayWayID" clearable placeholder="请选择支付方式">
              <el-option
                v-for="item in listPayWay"
                :key="item.PayWayId"
                :label="item.PayWayName"
                :value="item.PayWayId"
              />
            </el-select>
          </el-form-item>
        </el-col> -->
        <el-col :span="4" class="common_input">
          <el-form-item label="充值类型:" prop="ChargeTypeID">
            <el-select v-model="conModel.ChargeTypeID" clearable placeholder="请选择充值类型">
              <el-option key="0" label="全部" value="" />
              <el-option key="1" label="正常" value="1" />
              <el-option key="2" label="退气" value="2" />
              <el-option key="3" label="补气" value="3" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4" class="common_input">
          <el-form-item label="充值状态:" prop="ChargeStateId">
            <el-select v-model="conModel.ChargeStateId" clearable placeholder="请选择充值状态">
              <el-option key="0" label="全部" value="" />
              <el-option key="1" label="待确认" value="1" />
              <el-option key="2" label="等待远程命令返回" value="2" />
              <el-option key="3" label="成功" value="3" />
              <el-option key="4" label="失败" value="4" />
              <el-option key="5" label="被取消" value="5" />
            </el-select>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="1" class="sel_meter">
          <el-button size="mini" @click="meterPopup()">
            选择通信编号
          </el-button>
        </el-col> -->
        <el-col :span="1" class="common_query">
          <el-button size="mini" @click="getList('search')">
            查询
          </el-button>
        </el-col>
        <div class="common_right_btn common_query">
          <el-col :span="1">
            <el-button @click="exportReport()"><span>导出</span></el-button>
          </el-col>
        </div>
      </el-row>
    </el-form>
    <p v-show="statisticShow" class="statistic">充值数量合计：{{ statistic.SumChargeVolume }},充值金额合计：{{ statistic.SumChargeMoney }}</p>
    <div class="table_content">
      <el-table
        v-loading="listLoading"
        :data="list"
        fit
        style="width: 100%;"
        :stripe="true"
        >
        <el-table-column align="center" label="时间" width="160px">
          <template slot-scope="scope">
            {{ scope.row.ChargeTime | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="铭牌号" width="140px">
          <template slot-scope="scope">
            {{ scope.row.BarCode }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="客户名称" width="120px">
          <template slot-scope="scope">
            {{ scope.row.CustomerName }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="计量点" width="120px">
          <template slot-scope="scope">
            {{ scope.row.Address }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="价格名称" width="120px">
          <template slot-scope="scope">
            {{ scope.row.PriceName }}
          </template>
        </el-table-column>
         <el-table-column align="center" label="充值前金额" width="120px">
          <template slot-scope="scope">
            {{ scope.row.LastRemainMoney }}
          </template>
        </el-table-column>
         <el-table-column align="center" label="充值后金额" width="120px">
          <template slot-scope="scope">
            {{ scope.row.ThisRemainMoney }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="本次充值数量" width="120px">
          <template slot-scope="scope">
            {{ scope.row.ChargeVolume }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="本次充值金额" width="120px">
          <template slot-scope="scope">
            {{ scope.row.ChargeMoney }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="充值类型" width="120px">
          <template slot-scope="scope">
            {{ scope.row.ChargeTypeName }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="充值操作员" width="120px">
          <template slot-scope="scope">
            {{ scope.row.ChargeOperator }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="充值状态" width="120px">
          <template slot-scope="scope">
            {{ scope.row.ChargeStateName }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="180px">
          <template slot-scope="{row}">
            <span v-if="rightBtn !== -1" class="common_operation" @click="editPopup(row)" style="width: 100px">修改充值状态</span>
            <span class="common_operation" @click="detailsPopup(row)">详情</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="充值凭证" width="200px">
          <template slot-scope="{row}">
            <span class="common_operation" @click="ws_ajax_print(row,'print')">打印</span>
            <span class="common_operation" @click="ws_ajax_print(row,'pdf')">导出</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <pagination v-show="total>0" class="my_pagination" :total="total" :PageIndex.sync="Parameter.PageIndex" :PageSize.sync="Parameter.PageSize" @pagination="getList" />
    <!-- 详情 -->
    <el-dialog title="充值记录详情" :visible.sync="dialogDetails" class="newel-dialog details_pupop common_details">
      <div class="el-dialog__body">
        <el-form ref="dataForm" :model="tempDetails" class="demo-ruleForm common_popup" label-width="160px">
          <div class="common_details_bg"></div>
          <el-row :gutter="24">
            <el-col :span="8">
              <div class="grid-content bg-purple">
                <el-form-item label="充值时间:">
                  <span> {{ tempDetails.ChargeTime | dateFormat }} </span>
                </el-form-item>
                <el-form-item label="客户编号:">
                  <span> {{ tempDetails.CustomerName }} </span>
                </el-form-item>
                <el-form-item label="通信编号:">
                  <span> {{ tempDetails.CommNo }} </span>
                </el-form-item>
                <el-form-item label="表计厂家:">
                  <span> {{ tempDetails.FactoryName }} </span>
                </el-form-item>
                <el-form-item label="支付方式:">
                  <span> {{ tempDetails.PayWayName }} </span>
                </el-form-item>
                <el-form-item label="价格编号:">
                  <span> {{ tempDetails.PriceNo }} </span>
                </el-form-item>
                <el-form-item label="价格名称:">
                  <span> {{ tempDetails.PriceName }} </span>
                </el-form-item>
                <el-form-item label="系统充值次数:">
                  <span> {{ tempDetails.ChargeTimes }} </span>
                </el-form-item>
                <el-form-item label="上表充值次数:">
                  <span> {{ tempDetails.WriteCardChargeTimes }} </span>
                </el-form-item>
              </div>
            </el-col>
            <el-col :span="7">
              <div class="grid-content bg-purple">
                <el-form-item label="充值前金额:">
                  <span> {{ tempDetails.LastRemainMoney }} </span>
                </el-form-item>
                <el-form-item label="充值后金额:">
                  <span> {{ tempDetails.ThisRemainMoney }} </span>
                </el-form-item>
                <el-form-item label="本次充值数量:">
                  <span> {{ tempDetails.ChargeVolume }} </span>
                </el-form-item>
                <el-form-item label="本次充值金额:">
                  <span> {{ tempDetails.ChargeMoney }} </span>
                </el-form-item>
                <el-form-item label="上次剩余量:">
                  <span> {{ tempDetails.LastRemainVolume }} </span>
                </el-form-item>
                <el-form-item label="本次剩余量:">
                  <span> {{ tempDetails.ThisRemainVolume }} </span>
                </el-form-item>
                <el-form-item label="充值数量累计:">
                  <span> {{ tempDetails.TotalVolume }} </span>
                </el-form-item>
                <el-form-item label="充值金额累计:">
                  <span> {{ tempDetails.TotalMoney }} </span>
                </el-form-item>
              </div>
            </el-col>
            <el-col :span="7">
              <div class="grid-content bg-purple">
                <el-form-item label="交款金额:">
                  <span> {{ tempDetails.PayMoney }} </span>
                </el-form-item>
                <el-form-item label="当前价格:">
                  <span> {{ tempDetails.CurrentPrice }} </span>
                </el-form-item>
                <el-form-item label="当前价格区间:">
                  <span> {{ tempDetails.CurrentPriceLevel }} </span>
                </el-form-item>
                <el-form-item label="充值操作员:">
                  <span> {{ tempDetails.ChargeOperator }} </span>
                </el-form-item>
                <el-form-item label="充值类型:">
                  <span> {{ tempDetails.ChargeTypeName }} </span>
                </el-form-item>
                <el-form-item label="充值途径:">
                  <span> {{ tempDetails.ChargeWayName }} </span>
                </el-form-item>
                <el-form-item label="充值状态:">
                  <span> {{ tempDetails.ChargeStateName }} </span>
                </el-form-item>
                <el-form-item label="充值失败原因:">
                  <span> {{ tempDetails.FailureReason }} </span>
                </el-form-item>
                <!-- <el-form-item label="计算过程数据:">
                  <span> {{ tempDetails.CalcMsg }} </span>
                </el-form-item> -->
                <!-- <el-form-item label="远程命令审核:">
                  <span> {{ tempDetails.CmdAuditId }} </span>
                </el-form-item>
                <el-form-item label="物联网平台的控制命令:">
                  <span> {{ tempDetails.CtrlCmdId }} </span>
                </el-form-item> -->
                <!-- <el-form-item label="写卡返回数据:">
                  <span> {{ tempDetails.ICRetData }} </span>
                </el-form-item> -->
              </div>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button class="add_edit_btn determine" @click="dialogDetails = false">
          返回
        </el-button>
      </div>
    </el-dialog>
    <!-- 通信编号 -->
    <el-dialog title="表计信息" :visible.sync="dialogFormMeter" class="newel-dialog sel_meter_popup">
      <div class="el-dialog__body">
        <el-form :model="conModelMeter" label-width="72px" size="mini" class="search_content">
          <el-col :span="4" class="common_input">
            <el-form-item label="IC卡卡号:">
              <el-input v-model="conModelMeter.ICCardNo" clearable placeholder="请输入IC卡卡号" @keyup.enter.native="GetMeterInfo('search')" />
            </el-form-item>
          </el-col>
          <el-col :span="4" class="common_input">
            <el-form-item label="通信编号:">
              <el-input v-model="conModelMeter.Num" clearable placeholder="请输入通信编号" @keyup.enter.native="GetMeterInfo('search')" />
            </el-form-item>
          </el-col>
          <el-col :span="4" class="common_input">
            <el-form-item label="表计厂家:">
              <el-select v-model="conModelMeter.FactoryNo" clearable placeholder="请选择表计厂家" @change="GetMeterType(conModel.FactoryNo,'search')">
                <el-option
                  v-for="item in listFactory"
                  :key="item.FactoryNo"
                  :label="item.FactoryName"
                  :value="item.FactoryNo"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4" class="common_input">
            <el-form-item label="表计类型:">
              <el-select v-model="conModelMeter.Type" clearable placeholder="请选择表计类型">
                <el-option
                  v-for="item in listMeterType"
                  :key="item.MeterTypeNo"
                  :label="item.MeterTypeName"
                  :value="item.MeterTypeNo"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1" class="common_query">
            <el-button size="mini" @click="GetMeterInfo('search')">
              查询
            </el-button>
          </el-col>
        </el-form>
        <el-table
          v-loading="listLoading"
          :data="listMeter"
          fit
          style="width: 100%;"
          :stripe="true"
          >
          <el-table-column align="center" label="IC卡卡号">
          <template slot-scope="scope">
            {{ scope.row.CardNo }}
          </template>
          </el-table-column>
          <el-table-column align="center" label="通信编号">
            <template slot-scope="scope">
              {{ scope.row.CommNo }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="客户名称">
            <template slot-scope="scope">
              {{ scope.row.CustomerName }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="表计类型">
            <template slot-scope="scope">
              {{ scope.row.MeterTypeName }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="表计厂家">
            <template slot-scope="scope">
              {{ scope.row.FactoryName }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作">
            <template slot-scope="{row}">
              <span class="sel_operation" @click="selMeter(row)">选择编号</span>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="totalMeter>0" :total="totalMeter" :PageIndex.sync="Meter.PageIndex" :PageSize.sync="Meter.PageSize" @pagination="GetMeterInfo" />
      </div>
    </el-dialog>
    <!-- 修改充值状态弹窗 -->
    <el-dialog title="修改充值状态" :visible.sync="dialogFormEdit" class="newel-dialog common_add_edit_popup_one recharge_popup">
      <div class="el-dialog__body">
        <el-form ref="dataForm" :rules="rules" :model="common" class="demo-ruleForm common_popup" label-width="140px">
          <el-row :gutter="24">
            <el-col :span="15" :offset="3">
              <div class="grid-content bg-purple">
                <el-form-item label="登录密码:" prop="Password">
                  <el-input v-model="common.Password" clearable auto-complete="new-password" :type="this.pwdType" placeholder="请输入登录密码">
                    <i slot="suffix" class="el-icon-view el-icon-date" @click="pwdshow()" />
                  </el-input>
                </el-form-item>
                <el-form-item label="充值状态:" prop="ChargeStateId">
                  <el-select v-model="common.ChargeStateId" clearable placeholder="">
                    <el-option key="3" label="成功" value="3"></el-option>
                    <el-option key="4" label="失败" value="4"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="设置充值次数:" prop="SetChargeTimes">
                  <el-checkbox v-model="common.SetChargeTimes"></el-checkbox>
                </el-form-item>
                <el-form-item label="充值次数:" prop="ChargeTimes">
                  <el-input v-model="common.ChargeTimes" clearable placeholder="请输入充值次数" />
                </el-form-item>
                <el-form-item label="是否删除收费记录:" prop="DeleteReceipt" v-show="receiptShow">
                  <el-checkbox v-model="common.DeleteReceipt"></el-checkbox>
                </el-form-item>
                <el-form-item label="备注:" prop="FailureReason" v-if="common.ChargeStateId === '3' ? rules.FailureReason == [] : rules.FailureReason">
                  <el-input v-model="common.FailureReason" clearable placeholder="" />
                </el-form-item>
              </div>
            </el-col>
          </el-row>
        </el-form>
        <hr class="common_popup_border_bottom">
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button class="add_edit_btn cancel" @click="dialogFormEdit = false">
          取消
        </el-button>
        <el-button class="add_edit_btn determine" @click="ForceSetChargeState()">
          确定
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import { ChargeRecord, GetMeterInfo, GetPayWay, GetMeterType, GetFactoryType, ICCardCommit, UpdateChargeState, ForceSetChargeState, ChargeRecordStatistic, GetTemplateCode } from '@/api/basics'
import md5 from 'md5'
import moment from 'moment'
import { webapp_ws_ajax_run } from "@/utils/grwebapp"
import { getToken } from '@/utils/auth'

export default {
  name: 'Recharge',
  components: {
    Pagination
  },
  data() {
    return {
      Parameter: {
        PageSize: 10,
        PageIndex: 1,
        OrderBy: 'ChargeTime',
        isDesc: true
      },
      conModel: {
        StartTime: moment(new Date()).format('YYYY-MM-01 00:00'),
        EndTime: moment(new Date()).format('YYYY-MM-DD 23:59'),
        CommNo: '',
        BarCode: '',
        CustomerName: '',
        // PayWayID: '',
        ChargeTypeID: '',
        ChargeStateId: '', // 充值状态
        Address: ''
      },
      Meter: {
        PageSize: 10,
        PageIndex: 1,
        OrderBy: 'MeterId',
        isDesc: true
      },
      conModelMeter: {
        ICCardNo: '',
        Num: '',
        Type: '',
        FactoryNo: ''
      },
      conModelMeterCopy: {},
      conModelCopy: {},
      common: {
        CustomerId: '',
        MeterId: '',
        FactoryCode: '',
        MeterTypeCode: '',
        RecordId: '',
        Password: '',
        Timestamp: '', // 时间错
        ChargeStateId: '3', // 充值状态
        SetChargeTimes: false, // 是否要设置充值次数
        ChargeTimes: '', // 充值次数
        FailureReason: '', // 充值失败时，失败原因 必填
        DeleteReceipt: false, // 是否删除收费记录， 充值失败时，允许删除
      },
      listLoading: false,
      tempDetails: [],
      dialogDetails: false,
      dialogFormMeter: false,
      dialogFormEdit: false, // 修改充值状态
      list: [],
      listMeter: [],
      listFactory: [], // 表计厂家
      listMeterType: [], // 表计类型
      listPayWay: [], // 支付方式
      totalMeter: 0,
      total: 0,
      pwdType: 'password', // 密码
      showPwd: true,
      receiptShow: false, // 是否删除收费记录，显示隐藏
      statistic: [], // 数据统计
      statisticShow: false,
      code: '', // 导出模版
      rightBtn: 0,
      rules: {
        Password: [
          { required: true, message: '请输入登录密码', trigger: 'change' }
        ],
        ChargeStateId: [
          { required: true, message: '请选择充值状态', trigger: 'change' }
        ],
        FailureReason: [
          { required: true, message: '请输入充值失败原因', trigger: 'change' }
        ]
      }
    }
  },
  watch: {
    // 动态原因 rule
    'common.ChargeStateId': {
      handler(val) {
        this.common.FailureReason = ''
        if (val == '3') {
          // 是否删除收费记录
          this.receiptShow = false
          this.common.DeleteReceipt = false
          this.addRule('Remark', [{ required: false, message: '', trigger: 'change' }])
        } else if (val == '4') {
          this.receiptShow = true
          this.addRule('Remark', [{ required: true, message: '请输入充值失败原因', trigger: 'change' }])

        }
      }
    }
  },
  beforeMount() {
    this.rightBtn = localStorage.getItem('RoleRights').indexOf('3007')
    console.log(this.rightBtn)
  },
  created() {
    this.getList('search')
    this.GetPayWay()
    
  },
  methods: {
    exportReport() {
      let StartTime = null
      let EndTime = null
      let ChargeStateId = null
      let ChargeTypeID = null
      if (this.conModel.StartTime !== null) {
        StartTime = moment(this.conModel.StartTime).format('YYYY-MM-DD HH:mm')
      }
      if (this.conModel.EndTime !== null) {
        EndTime = moment(this.conModel.EndTime).format('YYYY-MM-DD HH:mm')
      }
      if (this.conModel.ChargeStateId !== '') {
        ChargeStateId = this.conModel.ChargeStateId
      }
      if (this.conModel.ChargeTypeID !== '') {
        ChargeTypeID = this.conModel.ChargeTypeID
      }
      let json = {
        ...this.conModel,
        StartTime: StartTime,
        EndTime: EndTime,
        ChargeStateId: ChargeStateId,
        ChargeTypeID: ChargeTypeID
      }
      let time = moment().format('YYYYMMDDHHmmss')
      var str = JSON.stringify(json)
      var enc = window.btoa(str)
      var encode = encodeURI(enc)
      let url = jsonData.urlContent
      let getUrl = url + '/api/Reports/Export/DownLoadTpl?templateCode=' + 'ChargeRecordExport' + '&token=' + getToken()
      let dataUrl = url + '/api/Reports/Export/ChargeRecordExport?p=' + encode + '&token=' + getToken()
      // 参数具体说明请参考帮助文档中的“WEB报表(B/S报表)->WEB报表客户端->启动参数说明”部分
      var args = {
        type: 'xls', // 
        showOptionDlg: true, // 如果不显示打印对话框而直接打印，将此行注释去掉即可
        report: getUrl,
        data: dataUrl,
        filename: '充值记录报表' + time,
      };
      
      webapp_ws_ajax_run(args)
    },
    ws_ajax_print(row,type) {
      let time = moment().format('YYYYMMDDHHmmss')
      let url = jsonData.urlContent
      let getUrl = url + '/api/Reports/Export/DownLoadTpl?templateCode=' + 'ChargeRecordInvoice' + '&token=' + getToken()
      let dataUrl = url + '/api/Reports/Export/ChargeRecordInvoice/' + row.RecordId + '?token=' + getToken()
      // 参数具体说明请参考帮助文档中的“WEB报表(B/S报表)->WEB报表客户端->启动参数说明”部分
      var args = {
        type: type, // 改成 xls ,pdf变成导出
        showOptionDlg: true, // 如果不显示打印对话框而直接打印，将此行注释去掉即可
        report: getUrl,
        data: dataUrl,
        filename: row.CustomerName + time,
        open: false
      };
      webapp_ws_ajax_run(args)
      return
    },
    pwdshow() {
      this.showPwd = !this.showPwd
      if (this.showPwd === false) {
        this.pwdType = 'text'
      } else {
        this.pwdType = 'password'
      }
    },
    // 自定义规则
    addRule(prop, rule) {
      this.$set(this.rules, prop, rule)
    },

    // 修改充值状态弹窗
    editPopup(row) {
      this.dialogFormEdit = true
      this.receiptShow = false
      this.common.CustomerId = row.CustomerId
      this.common.MeterId = row.MeterId
      this.common.FactoryCode = row.FactoryCode
      this.common.MeterTypeCode = row.MeterTypeCode
      this.common.RecordId = row.RecordId
      this.common.ChargeStateId = '3', // 充值状态
      this.common.SetChargeTimes = false // 是否要设置充值次数
      this.common.ChargeTimes = '', // 充值次数
      this.common.FailureReason = '' // 充值失败时，必填
      this.common.DeleteReceipt = false // 是否删除收费记录， 充值失败时，允许删除
      this.common.Password = ''
      this.common.Timestamp = ''
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    ForceSetChargeState() {
      this.$refs['dataForm'].validate((valid) => { 
        if (valid) {
          var temp = {
            ...this.common,
            ChargeStateId: parseInt(this.common.ChargeStateId),
            ChargeTimes: parseInt(this.common.ChargeTimes),
            Timestamp: Math.round(new Date().getTime()/1000),
            Password: md5(this.common.Password)
          }
          ForceSetChargeState(temp).then((res) => {
            if (res.State === 'success') {
              this.$message({
                message: '修改充值状态成功',
                type: 'success'
              })
              this.dialogFormEdit = false
              this.getList()
            }
          })
        }
      })
      
    },
    // 确认
    confirm() {
      let commit = {
        Method: 'WriteCard',
        CustomerId: this.common.CustomerId,
        MeterId: this.common.MeterId,
        RecordId: this.common.RecordId,
        CardData: {
          FactoryCode: this.common.FactoryCode,
          MeterTypeCode: this.common.MeterTypeCode,
          DataOutput: '',
          Sigin: '',
          SiginType: ''
        }
      }
      // 修改充值状态
      ICCardCommit(commit).then(res => {
        if(res.State == 'success') {
          this.$message({
            message: '修改充值状态成功',
            type: 'success'
          })
          this.getList()
          this.dialogFormEdit = false
        } else {
          this.$message({
            message: res.FailMessage,
            type: 'error'
          })
        }
      })
    },
    getList(init) {
      if (init === 'search') {
        this.Parameter.PageIndex = 1
        this.conModelCopy = {}
        // this.conModelCopy.PayWayID = this.conModel.PayWayID
      }
      if (this.conModel.StartTime !== null && init === 'search') {
        this.conModelCopy.StartTime = moment(this.conModel.StartTime).format('YYYY-MM-DD HH:mm')
      }
      if (this.conModel.EndTime !== null && init === 'search') {
        this.conModelCopy.EndTime = moment(this.conModel.EndTime).format('YYYY-MM-DD HH:mm')
      }
      if (this.conModel.CommNo.trim() !== '' && init === 'search') {
        this.conModelCopy.CommNo = this.conModel.CommNo.trim()
      }
      if (this.conModel.CustomerName.trim() !== '' && init === 'search') {
        this.conModelCopy.CustomerName = this.conModel.CustomerName.trim()
      }
      if (this.conModel.Address.trim() !== '' && init === 'search') {
        this.conModelCopy.Address = this.conModel.Address.trim()
      }
      if (this.conModel.ChargeStateId !== '' && init === 'search') {
        this.conModelCopy.ChargeStateId = this.conModel.ChargeStateId.trim()
      }
      if (this.conModel.ChargeTypeID !== '' && init === 'search') {
        this.conModelCopy.ChargeTypeID = this.conModel.ChargeTypeID.trim()
      }
      if (this.conModel.BarCode.trim() !== '' && init === 'search') {
        this.conModelCopy.BarCode = this.conModel.BarCode.trim()
      }
      this.listLoading = true
      var Parameter = {
        ...this.Parameter,
        ...this.conModelCopy
      }
      if (init === 'search') {
        ChargeRecordStatistic(Parameter).then(res => {
          this.statistic = res.Data
          this.statisticShow = true
        })
      }
      ChargeRecord(Parameter).then(res => {
        this.list = res.Data
        this.total = res.Total
        this.listLoading = false
      })
      
    },
    detailsPopup(row) {
      this.tempDetails = Object.assign({}, row)
      this.dialogDetails = true
    },
    // 选择通信编号 表格
    GetMeterInfo(init) {
      if (init === 'search') {
        this.Meter.PageIndex = 1
        this.conModelMeterCopy = {}
        this.conModelMeterCopy.FactoryNo = this.conModelMeter.FactoryNo
      }
      if (this.conModelMeter.ICCardNo.trim() !== '' && init === 'search') {
        this.conModelMeterCopy.ICCardNo = this.conModelMeter.ICCardNo.trim()
      }
      if (this.conModelMeter.Num.trim() !== '' && init === 'search') {
        this.conModelMeterCopy.Num = this.conModelMeter.Num.trim()
      }
      if (this.conModelMeter.Type.trim() !== '' && init === 'search') {
        this.conModelMeterCopy.Type = this.conModelMeter.Type.trim()
      }
      this.listLoading = true
      let Parameter = {
        ...this.Meter,
        ...this.conModelMeterCopy
      }
      GetMeterInfo(Parameter).then(res => {
        this.listMeter = res.Data
        this.totalMeter = res.Total
        this.listLoading = false
      })
    },
    // 选择表计
    selMeter(row) {
      if (row.CommNo === '') {
        this.$message({
          message: '没有通信编号',
          type: 'error'
        })
        return
      }
      this.conModel.CommNo = row.CommNo
      this.dialogFormMeter = false
    },
    // 表计信息弹窗
    meterPopup() {
      this.conModelMeter = {
        ICCardNo: '',
        Num: '',
        Type: '',
        FactoryNo: ''
      }
      this.Meter.PageIndex = 1
      this.conModelMeterCopy = {}
      this.listMeterType = []
      this.dialogFormMeter = true
      this.GetMeterInfo()
      this.GetFactoryType()
    },
    // 表计类型
    GetMeterType(FactoryNo,state) {
      if(state === 'search') {
        this.conModelMeter.Type = ''
      } else {
        this.conModelMeter.MeterTypeNo = ''
      }
      var Parameter = {
        PageSize: 99999,
        PageIndex: 1,
        OrderBy: 'CalcTypeCode',
        isDesc: true,
        FactoryNo: FactoryNo
      }
      GetMeterType(Parameter).then(res => {
        this.listMeterType = res.Data
      })
    },
    // 表计厂家
    GetFactoryType() {
      var Parameter = {
        PageSize: 99999,
        PageIndex: 1,
        OrderBy: 'FactoryNo',
        isDesc: true
      }
      GetFactoryType(Parameter).then(res => {
        this.listFactory = res.Data
      })
    },
    // 支付方式
    GetPayWay() {
      var Parameter = {
        PageSize: 99999,
        PageIndex: 1,
        OrderBy: 'PayWayId',
        isDesc: true
      }
      GetPayWay(Parameter).then(res => {
        this.listPayWay = res.Data
      })
    },
  }
}
</script>
